import { createApp } from 'vue'

import axios  from 'axios'
import router from './router'
import App from './App.vue'
import store from './store'
axios.defaults.baseURL ='http://apis.imooc.com/api'
axios.interceptors.request.use(config=>{
  store.commit('setLoading',true)
  store.commit('setError',{status:false,message:'error'})
    config.params={...config.params,icode:'6071467E1C2C4917'}
    if (config.data instanceof FormData) {
        config.data.append('icode', '6071467E1C2C4917')
      } else {
      // 普通的 body 对象，添加到 data 中
        config.data = { ...config.data, icode: '6071467E1C2C4917' }
      }
    return config
})
axios.interceptors.response.use(config =>{
  store.commit('setLoading',false)
  return config
}, e=>{
  const { error} = e.response.data
  store.commit('setError',{status:true,message:error})
  store.commit('setLoading',false)
  return Promise.reject(error)
})
// axios.get('/columns').then(resp=>{
//     console.log(resp.data)
// })

const app = createApp(App)


app.use(router)
app.use(store)
app.mount('#app')
